import React from "react";
import SearchHeader from "./component/SearchHeader";
import TheTable from "@/components/TheTable";
import "../style/style.less";
import ThePagination from "../../../components/ThePagination";
import _ from 'lodash'
import { apiGetActivityCodeList, apiPostActivityCodeEdit } from '@/request/activityCode'
import { Button, Form, Select, Space } from "antd";
import { exportTable } from "../../../utils/exportTable";
import logoUrl from '@/assets/images/logoIcon.png'
class Security extends React.Component {
  state = {
    columns: [
      {
        title: "批次号",
        dataIndex: "batchNo",
        key: "batchNo",
      },
      {
        title: "链接地址",
        dataIndex: "antifakeCode",
        key: "antifakeCode",
        render:(text,render)=>{
          return <div>http://www.hqmpet.com/share/#/pages/antiFake/index?short_url={render.batchNo}_{render.antifakeCode}</div>
        }
      },
      {
        title: "已扫次数",
        dataIndex: "useNum",
        key: "useNum",
      },
    ],
    dataSource: [],
    pageData: {
      pageNo: 1,
      pageSize: 10,
    },
    total: 0,
    searchValue: {},
    loading: false,
    options: null
  };
  async componentDidMount() {
    await this.getData()
  }
  getData = async () => {
    this.setState({ loading: true })
    const { pageData, searchValue } = this.state
    let res = await React.$post("/management/tAntifakeCodeCheck/page",{ ...pageData, ...searchValue })
    // console.log(res)
    if (res.code === 0 && res.data) {

      this.setState({ dataSource: res.data, pageData: { pageNo: res.pageNo, pageSize: res.pageSize }, total: res.totalCount, loading: false })
    }
  }
  getValue = (value) => {
    this.setState({
      searchValue: value,
      pageData: {
        pageNo: 1,
        pageSize: 10
      }
    }, () => {
      this.getData()
    })
  }
  pageChange = (pageNo, pageSize) => {
    this.setState({
      pageData: {
        pageNo,
        pageSize
      }
    }, () => {
      this.getData()
    })
  };

  render() {
    const {
      columns,
      dataSource,
      pageData: { pageNo, pageSize },
      total,
      loading,
      options
    } = this.state;
    return (
      <div className={"p-layout-box commodity-content"}>
        <SearchHeader toAdd={() => this.props.history.push('/activityCode/Security/add')}
        toHistory={() => this.props.history.push('/activityCode/Security/list')} exportAll={() => this.exportAll()} history={this.props.history} getValue={this.getValue} />
        <div className="p-layout-content-pagination">
          <TheTable
            scroll={{ x: "max-content", y: '63vh' }}
            columns={columns}
            dataSource={dataSource}
            loading={loading}
          />
          <ThePagination
            pageNo={pageNo}
            pageSize={pageSize}
            total={total}
            pageChange={this.pageChange}
          />
        </div>
      </div>
    );
  }
}

export default Security;
